{% extends 'iframe/basePlus.html.twig' %}
{% block cardHeader %}权限分配<a href="{{ path_index }}" class="layui-btn layui-btn-sm dry-right">{{ language('index') }}</a>{% endblock %}
{% block cardBody %}
<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">用户组</label>
        <div class="layui-input-block">
            <input type="hidden" class="layui-input" name="id" value="{{ id }}" onfocus="this.blur()">
            <input type="text" class="layui-input" value="{{ group.dry_name }}" onfocus="this.blur()">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权限集</label>
        <div class="layui-input-block">
            <table class="layui-table">
                <thead>
                <tr>
                    <th>名称</th>
                    <th>全选|反选</th>
                    <th>列表</th>
                    <th>查看</th>
                    <th>添加</th>
                    <th>编辑</th>
                    <th>删除</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td></td>
                    <td></td>
                    <td>
                        <div class="layui-btn-group">
                            <button type="button" class="layui-btn" onclick="checkPermission('vertical-group', 'index', 1)">全选</button>
                            <button type="button" class="layui-btn" onclick="checkPermission('vertical-group', 'index', 0)">反选</button>
                        </div>
                    </td>
                    <td>
                        <div class="layui-btn-group">
                            <button type="button" class="layui-btn" onclick="checkPermission('vertical-group', 'show', 1)">全选</button>
                            <button type="button" class="layui-btn" onclick="checkPermission('vertical-group', 'show', 0)">反选</button>
                        </div>
                    </td>
                    <td>
                        <div class="layui-btn-group">
                            <button type="button" class="layui-btn" onclick="checkPermission('vertical-group', 'new', 1)">全选</button>
                            <button type="button" class="layui-btn" onclick="checkPermission('vertical-group', 'new', 0)">反选</button>
                        </div>
                    </td>
                    <td>
                        <div class="layui-btn-group">
                            <button type="button" class="layui-btn" onclick="checkPermission('vertical-group', 'edit', 1)">全选</button>
                            <button type="button" class="layui-btn" onclick="checkPermission('vertical-group', 'edit', 0)">反选</button>
                        </div>
                    </td>
                    <td>
                        <div class="layui-btn-group">
                            <button type="button" class="layui-btn" onclick="checkPermission('vertical-group', 'delete', 1)">全选</button>
                            <button type="button" class="layui-btn" onclick="checkPermission('vertical-group', 'delete', 0)">反选</button>
                        </div>
                    </td>
                </tr>
                {% for item in list %}
                <!---->
                <tr>
                    <td>{{ item.text }}</td>
                    <td>
                        <div class="layui-btn-group">
                            <button type="button" class="layui-btn" onclick="checkPermission('horizontal-group', '{{ item.model }}', 1)">全选</button>
                            <button type="button" class="layui-btn" onclick="checkPermission('horizontal-group', '{{ item.model }}', 0)">反选</button>
                        </div>
                    </td>
                    <td>{% if item.common.index.show %} <input type="checkbox" name="permission[]" value="{{ item.common.index.permission }}"  horizontal-group="{{ item.common.index.horizontal_group }}"  vertical-group="{{ item.common.index.vertical_group }}"  lay-skin="primary" title="{{ item.common.index.text }}">{% endif %}</td>
                    <td>{% if item.common.show.show %}  <input type="checkbox" name="permission[]" value="{{ item.common.show.permission }}"   horizontal-group="{{ item.common.show.horizontal_group }}"   vertical-group="{{ item.common.show.vertical_group }}"   lay-skin="primary" title="{{ item.common.show.text }}">{% endif %}</td>
                    <td>{% if item.common.new.show %}   <input type="checkbox" name="permission[]" value="{{ item.common.new.permission }}"    horizontal-group="{{ item.common.new.horizontal_group }}"    vertical-group="{{ item.common.new.vertical_group }}"    lay-skin="primary" title="{{ item.common.new.text }}">{% endif %}</td>
                    <td>{% if item.common.edit.show %}  <input type="checkbox" name="permission[]" value="{{ item.common.edit.permission }}"   horizontal-group="{{ item.common.edit.horizontal_group }}"   vertical-group="{{ item.common.edit.vertical_group }}"   lay-skin="primary" title="{{ item.common.edit.text }}">{% endif %}</td>
                    <td>{% if item.common.delete.show %}<input type="checkbox" name="permission[]" value="{{ item.common.delete.permission }}" horizontal-group="{{ item.common.delete.horizontal_group }}" vertical-group="{{ item.common.delete.vertical_group }}" lay-skin="primary" title="{{ item.common.delete.text }}">{% endif %}</td>
                </tr>
                {% if item.extension is not empty %}
                <tr>
                    <td></td>
                    <td>
                        <div class="layui-btn-group">
                            <button type="button" class="layui-btn" onclick="checkPermission('extension-group', '{{ item.model }}', 1)">全选</button>
                            <button type="button" class="layui-btn" onclick="checkPermission('extension-group', '{{ item.model }}', 0)">反选</button>
                        </div>
                    </td>
                    <td colspan="5">
                        {% for rs in item.extension %}
                        <input type="checkbox" name="permission[]" value="{{ rs.permission }}" extension-group="{{ rs.extension_group }}" lay-skin="primary" title="{{ rs.text }}">
                        {% endfor %}
                    </td>
                </tr>
                {% endif %}
                <!---->
                {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <a href="javascript:void(0);" class="layui-btn" id="submit">确定</a>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
{% endblock %}
{% block footer %}
<script>
var $ = null;
layui.use(['element', 'form', 'jquery', 'layer'], function(element, form, jquery, layer){
    $ = jquery;

    $("#submit").click(function(){
        var data = $('form').serializeArray();
        $.post("{{ get_domain() }}/Api/GroupPermission/new", data, function(json){
            layer.msg(json.msg, function(){
                window.location.reload();
            });
        });
    });

    /**/
    var list = '{{ assigned }}'.split(",");
    for(var i in list){
        var name = list[i];
        $("[value='" + name + "']").attr("checked", true);
    }
    form.render("checkbox");

});
</script>
{% endblock %}